<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>类型模板管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/plugins/select2/select2.css"/>
    <link rel="stylesheet" href="/plugins/select2/select2-bootstrap.css"/>
    <script src="/plugins/select2/select2.min.js" type="text/javascript"></script>

</head>

<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->

<div class="box-header with-border">
    <h3 class="box-title">商品类型模板管理</h3>
</div>

<div class="box-body">

    <!-- 数据表格 -->
    <div class="table-box">

        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="新建" data-toggle="modal"
                            data-target="#editModal"><i class="fa fa-file-o"></i> 新建
                    </button>
                    <button type="button" class="btn btn-default" onclick="deleteallTbTypeTemplate()" title="删除"><i class="fa fa-trash-o"></i> 批量删除</button>

                    <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i
                            class="fa fa-refresh"></i> 刷新
                    </button>
                </div>
            </div>
        </div>
        <div class="box-tools pull-right">
            <div class="has-feedback">
                分类模板名称：<input id="namebyname">
                <button class="btn btn-default" onclick="getall()">查询</button>
            </div>
        </div>
        <!--工具栏/-->

        <!--数据列表-->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="" style="padding-right:0px">
                    <input id="selall" type="checkbox" onclick="reversal()" class="icheckbox_square-blue">
                </th>
                <th class="sorting_asc">模板ID</th>
                <th class="sorting">分类模板名称</th>
                <th class="sorting">关联品牌</th>
                <th class="sorting">关联规格</th>
                <th class="sorting">扩展属性</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <!--复选框反转-->
            <script type="text/javascript">
                function reversal() {
                    $("[name=checkbox]").prop("checked", $("#selall").prop("checked"))
                }
            </script>
            <tbody id="TbTypeTemplate">
            </tbody>
        </table>
        <!--数据列表/-->

        <!--加载商品类型模板内容-->
        <script type="text/javascript">
            //加载商品类型模板内容
            $.ajax({
                url: "/TbTypeTemplate/TbTypeTemplateshowall",
                data: {},
                type: "post",
                dataType: "json",
                async: false,
                success: function (pm) {
                    var TbTypeTemplate = pm.data.rows;
                    var TbTypeTemplateList = '';
                    $(TbTypeTemplate).each(function (i, e) {
                        var specIdstexts = ''
                        $(JSON.parse(e.specIds)).each(function (i1, v1) {
                            specIdstexts += v1.text + ','
                        })
                        var brandIdstexts = ''
                        $(JSON.parse(e.brandIds)).each(function (i2, v2) {
                            brandIdstexts += v2.text + ','
                        })
                        var customAttributeItemstexts = ''
                        $(JSON.parse(e.customAttributeItems)).each(function (i3, v3) {
                            customAttributeItemstexts += v3.text + ','
                        })
                        TbTypeTemplateList += '<tr>'
                        TbTypeTemplateList += '<td><input type = "checkbox" name="checkbox" value="' + e.id + '"></td>'
                        TbTypeTemplateList += '<td>' + e.id + '</td>'
                        TbTypeTemplateList += '<td>' + e.name + '</td>'
                        TbTypeTemplateList += '<td>' + specIdstexts.slice(0, -1) + '</td>'
                        TbTypeTemplateList += '<td>' + brandIdstexts.slice(0, -1) + '</td>'
                        TbTypeTemplateList += '<td>' + customAttributeItemstexts.slice(0, -1) + '</td>'
                        TbTypeTemplateList += '<td className="text-center">'
                        TbTypeTemplateList += '<button type="button" className="btn bg-olive btn-xs" onclick="echo(' + e.id + ')" data-toggle="modal"data-target="#updateeditModal">修改'
                        TbTypeTemplateList += '</button>'
                        TbTypeTemplateList += ' <button type="button" onclick="deleteTbTypeTemplate(' + e.id + ')">删除</button>'
                        TbTypeTemplateList += '</td>'
                        TbTypeTemplateList += '</tr>'
                    })
                    TbTypeTemplateList += '<tr><td colspan="7">'
                    TbTypeTemplateList += '<input type="button" value="首页" onclick="skip(0)"> '
                    TbTypeTemplateList += '<input type="button" value="上一页" onclick="skip(1)"> '
                    TbTypeTemplateList += '<span id="pageNum">' + pm.data.pageNum + '</span> / <span id="pages">' + pm.data.pages
                    TbTypeTemplateList += '</span> <input type="button" value="下一页" onclick="skip(2)"> '
                    TbTypeTemplateList += '<input type="button" value="末页" onclick="skip(3)"> '
                    TbTypeTemplateList += '</td></tr>'
                    $("#TbTypeTemplate").html(TbTypeTemplateList);
                },
                error: function () {
                    alert("系统异常")
                }
            })

            //换页逻辑
            function skip(pm) {
                let pageNum = $("#pageNum").text();
                let pages = $("#pages").text();
                if (pm == 0) {
                    if (pageNum == 1) {
                        alert("已是首页")
                    } else {
                        $("#pageNum").text(1)
                        getall()
                    }
                } else if (pm == 1) {
                    if (pageNum == 1) {
                        alert("已是第一页")
                    } else {
                        $("#pageNum").text(pageNum - 1)
                        getall()
                    }
                } else if (pm == 2) {
                    if (pageNum == pages) {
                        alert("已是最后一页")
                    } else {
                        $("#pageNum").text(parseInt(pageNum) + 1)
                        getall()
                    }
                } else if (pm == 3) {
                    if (pageNum == pages) {
                        alert("已是末页")
                    } else {
                        $("#pageNum").text(pages)
                        getall()
                    }
                }
            }

            //加载换页后商品类型模板内容
            function getall() {
                //加载商品类型模板表内容
                let pageNum = $("#pageNum").text();
                let pages = $("#pages").text();
                let name = $("#namebyname").val();
                $.ajax({
                    url: "/TbTypeTemplate/TbTypeTemplateshowall",
                    data: {pageNum: pageNum, pages: pages, name: name},
                    type: "post",
                    dataType: "json",
                    async: false,
                    success: function (pm) {
                        var TbTypeTemplate = pm.data.rows;
                        var TbTypeTemplateList = '';
                        $(TbTypeTemplate).each(function (i, e) {
                            var specIdstexts = ''
                            $(JSON.parse(e.specIds)).each(function (i1, v1) {
                                specIdstexts += v1.text + ','
                            })
                            var brandIdstexts = ''
                            $(JSON.parse(e.brandIds)).each(function (i2, v2) {
                                brandIdstexts += v2.text + ','
                            })
                            var customAttributeItemstexts = ''
                            $(JSON.parse(e.customAttributeItems)).each(function (i3, v3) {
                                customAttributeItemstexts += v3.text + ','
                            })
                            TbTypeTemplateList += '<tr>'
                            TbTypeTemplateList += '<td><input type = "checkbox" name="checkbox" value="' + e.id + '"></td>'
                            TbTypeTemplateList += '<td>' + e.id + '</td>'
                            TbTypeTemplateList += '<td>' + e.name + '</td>'
                            TbTypeTemplateList += '<td>' + specIdstexts.slice(0, -1) + '</td>'
                            TbTypeTemplateList += '<td>' + brandIdstexts.slice(0, -1) + '</td>'
                            TbTypeTemplateList += '<td>' + customAttributeItemstexts.slice(0, -1) + '</td>'
                            TbTypeTemplateList += '<td className="text-center">'
                            TbTypeTemplateList += '<button type="button" className="btn bg-olive btn-xs" onclick="echo(' + e.id + ')" data-toggle="modal"data-target="#updateeditModal">修改'
                            TbTypeTemplateList += '</button>'
                            TbTypeTemplateList += ' <button type="button" onclick="deleteTbTypeTemplate(' + e.id + ')">删除</button>'
                            TbTypeTemplateList += '</td>'
                            TbTypeTemplateList += '</tr>'
                        })
                        TbTypeTemplateList += '<tr><td colspan="7">'
                        TbTypeTemplateList += '<input type="button" value="首页" onclick="skip(0)"> '
                        TbTypeTemplateList += '<input type="button" value="上一页" onclick="skip(1)"> '
                        TbTypeTemplateList += '<span id="pageNum">' + pm.data.pageNum + '</span> / <span id="pages">' + pm.data.pages
                        TbTypeTemplateList += '</span> <input type="button" value="下一页" onclick="skip(2)"> '
                        TbTypeTemplateList += '<input type="button" value="末页" onclick="skip(3)"> '
                        TbTypeTemplateList += '</td></tr>'
                        $("#TbTypeTemplate").html(TbTypeTemplateList);
                    },
                    error: function () {
                        alert("系统异常")
                    }
                })
            }
        </script>
    </div>
    <!-- 数据表格 /-->


</div>
<!-- /.box-body -->


<!-- 编辑窗口 添加-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">商品类型模板编辑</h3>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped" width="800px">
                    <tr>
                        <td>商品类型</td>
                        <td><input class="form-control" placeholder="商品类型" id="name"></td>
                    </tr>
                    <tr>
                        <td>关联品牌</td>
                        <td id="pinpai">
                        </td>
                    </tr>
                    <tr>
                        <td>关联规格</td>
                        <td id="guige">
                        </td>
                    </tr>
                    <tr>
                        <td>扩展属性</td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" onclick="addhtmls()" title="新增扩展属性"><i
                                        class="fa fa-file-o"></i> 新增扩展属性
                                </button>
                                <button type="button" class="btn btn-default" onclick="deletehtmlsall()" title="删除已选属性">
                                    <i
                                            class="fa fa-file-o"></i> 删除已选属性
                                </button>
                            </div>
                            <table class="table table-bordered table-striped" width="800px">
                                <thead>
                                <tr>
                                    <td><input type="checkbox" class="icheckbox_square-blue" id="selalls"
                                               onclick="reversals()"></td>
                                    <td>属性名称</td>
                                    <td>操作</td>
                                </tr>
                                </thead>
                                <tbody id="tbodys">
                                <tr>
                                    <td><input type="checkbox" name="checkboxs" class="icheckbox_square-blue"></td>
                                    <td><input class="form-control" placeholder="属性名称"></td>
                                    <td>
                                        <button type="button" class="btn btn-default" onclick="deletehtmls(this)"
                                                title="删除"><i
                                                class="fa fa-trash-o"></i> 删除
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td><input type="checkbox" name="checkboxs" class="icheckbox_square-blue"></td>
                                    <td><input class="form-control" placeholder="属性名称"></td>
                                    <td>
                                        <button type="button" class="btn btn-default" onclick="deletehtmls(this)"
                                                title="删除"><i
                                                class="fa fa-trash-o"></i> 删除
                                        </button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
            <script type="text/javascript">

                //添加html元素
                function addhtml() {
                    var htmls = '<tr><td><input type="checkbox" name="checkboxss" class="icheckbox_square-blue"></td>' +
                        '<td><input class="form-control" placeholder="属性名称"></td>' +
                        '<td><button type="button" class="btn btn-default" onclick="deletehtml(this)" title="删除"><i class="fa fa-trash-o"></i> 删除</button></td></tr>';
                    $("#tbodyss").append(htmls)
                }

                <!--删除html元素-->
                function deletehtml(pm) {
                    if ($("#tbodyss").find('tr').length == 1) {
                        alert("至少要留一个规格选项")
                        return
                    }
                    var parentNode = pm.parentNode.parentNode;
                    $("#tbodyss")[0].removeChild(parentNode);
                }

                <!--删除已选html元素-->
                function deletehtmlsallss() {
                    var ii = 0
                    $("[name=checkboxss]").each(function (i, v) {
                        if ($(v).prop("checked") == true) {
                            ii++
                        }
                    })
                    if ($("#tbodyss").find('tr').length == ii) {
                        alert("至少要留一个规格选项")
                        return
                    }
                    $("[name=checkboxss]").each(function (i, v) {
                        if ($(v).prop("checked") == true) {
                            var parentNode = v.parentNode.parentNode;
                            $("#tbodyss")[0].removeChild(parentNode);
                        }
                    })
                }

                //复选框反选属性(弹框版)
                function reversalss() {
                    $("[name=checkboxss]").prop("checked", $("#selallss").prop("checked"))
                }

                //-------------
                //添加html元素
                function addhtmls() {
                    var htmls = '<tr><td><input type="checkbox" name="checkboxs" class="icheckbox_square-blue"></td>' +
                        '<td><input class="form-control" placeholder="属性名称"></td>' +
                        '<td><button type="button" class="btn btn-default" onclick="deletehtmls(this)" title="删除"><i class="fa fa-trash-o"></i> 删除</button></td></tr>';
                    $("#tbodys").append(htmls)
                }

                <!--删除html元素-->
                function deletehtmls(pm) {
                    if ($("#tbodys").find('tr').length == 1) {
                        alert("至少要留一个规格选项")
                        return
                    }
                    var parentNode = pm.parentNode.parentNode;
                    $("#tbodys")[0].removeChild(parentNode);
                }

                <!--删除已选html元素-->
                function deletehtmlsall() {
                    var ii = 0
                    $("[name=checkboxs]").each(function (i, v) {
                        if ($(v).prop("checked") == true) {
                            ii++
                        }
                    })
                    if ($("#tbodys").find('tr').length == ii) {
                        alert("至少要留一个规格选项")
                        return
                    }
                    $("[name=checkboxs]").each(function (i, v) {
                        if ($(v).prop("checked") == true) {
                            var parentNode = v.parentNode.parentNode;
                            $("#tbodys")[0].removeChild(parentNode);
                        }
                    })
                }

                //复选框反选属性(弹框版)
                function reversals() {
                    $("[name=checkboxs]").prop("checked", $("#selalls").prop("checked"))
                }
            </script>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" onclick="addTbTypeTemplate()" aria-hidden="true">
                    保存
                </button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
    <!--关联品牌,关联规格回显到input-->
    <script type="text/javascript">
        $.ajax({//规格
            url: "/TbSpecificationOption/TbSpecificationshow",
            data: {},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                var guiges = '<select style="width: 100%" id="aa" multiple>'
                $(pm.data).each(function (i, e) {
                    guiges += '<option value="' + e.id + '">' + e.specName + '</option>'
                })
                guiges += '</select>'
                $("#guige").html(guiges);
                $("#aa").select2()
            },
            error: function () {
                alert("系统异常")
            }
        })

        $.ajax({//品牌
            url: "/TbBrand/TbBrandshow",
            data: {},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                var pinpais = '<select style="width: 100%" id="bb" multiple>'
                $(pm.data).each(function (i, e) {
                    pinpais += '<option value="' + e.id + '">' + e.name + '</option>'
                })
                pinpais += '</select>'
                $("#pinpai").html(pinpais);
                $("#bb").select2()
            },
            error: function () {
                alert("系统异常")
            }
        })
    </script>
</div>

<!-- 编辑窗口 修改-->
<div class="modal fade" id="updateeditModal" tabindex="-1" role="dialog" aria-labelledby="updatemyModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="updatemyModalLabel">商品类型模板编辑</h3>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped" width="800px">
                    <tr>
                        <td>商品类型<input type="hidden" id="id"></td>
                        <td><input class="form-control" placeholder="商品类型" id="names"></td>
                    </tr>
                    <tr>
                        <td>关联品牌</td>
                        <td id="pinpais">
                        </td>
                    </tr>
                    <tr>
                        <td>关联规格</td>
                        <td id="guiges">
                        </td>
                    </tr>
                    <tr>
                        <td>扩展属性</td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" onclick="addhtml()" title="新增扩展属性"><i
                                        class="fa fa-file-o"></i> 新增扩展属性
                                </button>
                                <button type="button" class="btn btn-default" onclick="deletehtmlsallss()"
                                        title="删除已选属性">
                                    <i
                                            class="fa fa-file-o"></i> 删除已选属性
                                </button>
                            </div>
                            <table class="table table-bordered table-striped" width="800px">
                                <thead>
                                <tr>
                                    <td><input type="checkbox" class="icheckbox_square-blue" id="selallss"
                                               onclick="reversalss()"></td>
                                    <td>属性名称</td>
                                    <td>操作</td>
                                </tr>
                                </thead>
                                <tbody id="tbodyss">
                                <tr>
                                    <td><input type="checkbox" name="checkboxss" class="icheckbox_square-blue"></td>
                                    <td><input class="form-control" placeholder="属性名称"></td>
                                    <td>
                                        <button type="button" class="btn btn-default" onclick="deletehtml(this)"
                                                title="删除"><i
                                                class="fa fa-trash-o"></i> 删除
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td><input type="checkbox" name="checkboxss" class="icheckbox_square-blue"></td>
                                    <td><input class="form-control" placeholder="属性名称"></td>
                                    <td>
                                        <button type="button" class="btn btn-default" onclick="deletehtml(this)"
                                                title="删除"><i
                                                class="fa fa-trash-o"></i> 删除
                                        </button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" onclick="updateTbTypeTemplate()"
                        aria-hidden="true">
                    保存
                </button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
    <!--关联品牌,关联规格回显到input-->
    <script type="text/javascript">
        $.ajax({//规格
            url: "/TbSpecificationOption/TbSpecificationshow",
            data: {},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                var guiges = '<select style="width: 100%" id="cc" multiple>'
                $(pm.data).each(function (i, e) {
                    guiges += '<option value="' + e.id + '">' + e.specName + '</option>'
                })
                guiges += '</select>'
                $("#guiges").html(guiges);
                $("#cc").select2()
            },
            error: function () {
                alert("系统异常")
            }
        })

        $.ajax({//品牌
            url: "/TbBrand/TbBrandshow",
            data: {},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                var pinpais = '<select style="width: 100%" id="dd" multiple>'
                $(pm.data).each(function (i, e) {
                    pinpais += '<option value="' + e.id + '">' + e.name + '</option>'
                })
                pinpais += '</select>'
                $("#pinpais").html(pinpais);
                $("#dd").select2()
            },
            error: function () {
                alert("系统异常")
            }
        })
    </script>
</div>
<script type="text/javascript">

    //添加模板信息
    function addTbTypeTemplate() {
        var name = $("#name").val();
        if ('' == name || name == null) {
            alert("商品类型不能为空")
            return
        }
        var select2 = $("#aa").select2('data');
        var specIds = []
        $(select2).each(function (i, e) {
            var specIdss = {id: e.id, text: e.text}
            specIds.push(specIdss)
        })
        var select = $("#bb").select2('data');
        var brandIds = []
        $(select).each(function (i, e) {
            var brandIdss = {id: e.id, text: e.text}
            brandIds.push(brandIdss)
        })
        var customAttributeItems = [];
        $("#tbodys").find('tr').each(function (i, v) {
            var t = $($(v).find('td')[1]).find('input').val();
            customAttributeItems.push({text: t})
        })

        $.ajax({
            url: "/TbTypeTemplate/addTbTypeTemplate",
            data: {
                name: name,
                specIds: JSON.stringify(specIds),
                brandIds: JSON.stringify(brandIds),
                customAttributeItems: JSON.stringify(customAttributeItems)
            },
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                alert(pm.message)
                getall()
            },
            error: function () {
                alert("系统异常")
            }
        })
    }

    <!--模板数据回显-->
    function echo(id) {
        $.ajax({
            url: "/TbTypeTemplate/showecho",
            data: {id: id},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                $("#id").val(pm.data.id)
                $("#names").val(pm.data.name)
                var arr = []
                $(JSON.parse(pm.data.specIds)).each(function (i, e) {
                    arr.push(e.id)
                })
                $("#cc").val(arr).trigger('change')
                var arr1 = []
                $(JSON.parse(pm.data.brandIds)).each(function (i, e) {
                    arr1.push(e.id)
                })
                $("#dd").val(arr1).trigger('change')
                $("#specNamebyid").val(pm.data.specName)
                var s = ''
                var parse = JSON.parse(pm.data.customAttributeItems);
                for (let i = 0; i < parse.length; i++) {
                    s += '<tr><td><input type="checkbox" name="checkboxss" class="icheckbox_square-blue"></td>' +
                        '<td><input class="form-control" placeholder="属性名称" value="' + parse[i].text + '"></td>' +
                        '<td><button type="button" class="btn btn-default" onclick="deletehtml(this)" title="删除"><i class="fa fa-trash-o"></i> 删除</button></td></tr>';
                }
                $("#tbodyss").html(s)
            },
            error: function () {
                alert("系统异常")
            }
        })
    }

    <!--修改模板数据-->
    function updateTbTypeTemplate() {
        var id = $("#id").val();
        var name = $("#names").val();
        if ('' == name || name == null) {
            alert("商品类型不能为空")
            return
        }
        var select2 = $("#cc").select2('data');
        var specIds = []
        $(select2).each(function (i, e) {
            var specIdss = {id: e.id, text: e.text}
            specIds.push(specIdss)
        })
        var select = $("#dd").select2('data');
        var brandIds = []
        $(select).each(function (i, e) {
            var brandIdss = {id: e.id, text: e.text}
            brandIds.push(brandIdss)
        })
        var customAttributeItems = [];
        $("#tbodyss").find('tr').each(function (i, v) {
            var t = $($(v).find('td')[1]).find('input').val();
            customAttributeItems.push({text: t})
        })
        console.log(id);
        console.log(name);
        console.log(JSON.stringify(specIds));
        console.log(JSON.stringify(brandIds));
        console.log(JSON.stringify(customAttributeItems));
        $.ajax({
            url: "/TbTypeTemplate/updateTbTypeTemplate",
            data: {
                id: id, name: name,
                specIds: JSON.stringify(specIds),
                brandIds: JSON.stringify(brandIds),
                customAttributeItems: JSON.stringify(customAttributeItems)
            },
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                alert(pm.message)
                getall()
            },
            error: function () {
                alert("系统异常")
            }
        })
    }

    //模板数据删除
    function deleteTbTypeTemplate(id) {
        if (confirm("你确定要删除吗?")) {
            $.ajax({
                url: "/TbTypeTemplate/deleteTbTypeTemplate",
                data: {id: id},
                type: "post",
                dataType: "json",
                async: false,
                success: function (pm) {
                    alert(pm.message)
                    getall()
                },
                error: function () {
                    alert("系统异常")
                }
            })
        }
    }

    //多条数据删除
    function deleteallTbTypeTemplate() {
        var ids = []
        $("[name=checkbox]").each(function (i, e) {
            if ($(e).prop("checked")) {
                ids.push($(e).val())
            }
        })
        if (ids == '') {
            alert("请先选择要删除的品牌")
            return
        }
        if (confirm("你确定要删除吗?")) {
            $.ajax({
                url: "/TbTypeTemplate/deleteallTbTypeTemplate",
                data: {ids: ids},
                type: "post",
                dataType: "json",
                async: false,
                success: function (pm) {
                    alert(pm.message)
                    getall()
                },
                error: function () {
                    alert("系统异常")
                }
            })
        }
    }
</script>
</body>

</html>